/**
 * 
 */
package com.smartwork.common.utils;

/**
 * @author Administrator
 * 
 */
public class RandUtil {

	public static String getNumberRandStr(Integer length) {
		String str = "";
		while (str.length() != length) {
			str = (Math.random() + "").substring(2, 2 + length);
		}
		return str;
	}

	public static String getRandStr(Integer length) {
		String str = "";
		while (str.length() != length) {
			str = str + getRandomChar();
		}
		return str;
	}

	public static String getRandomChar() {
		int index = (int) Math.round(Math.random() * 2);

		String randChar = "";
		switch (index) {
		// case 0:// 大写字符
		// randChar = String.valueOf((char) Math
		// .round(Math.random() * 25 + 65));
		// break;
		case 1:// 小写字符
			randChar = String.valueOf((char) Math.round(Math.random() * 25 + 97));
			break;
		default:// 数字
			randChar = String.valueOf(Math.round(Math.random() * 9));
			break;
		}
		return randChar;
	}

	public static int getRandNum(int low, int hight) {
		int num = (int) (Math.random() * (hight - low + 1));
		num = num + low;
		return num;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for (int i = 0; i < 100; i++) {
			System.out.println(getRandNum(4, 10));
		}

	}

}
